<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <title>Title</title>
    <script src="node_modules/clipboard/dist/clipboard.js"></script>
    <style>
        .copy{
            padding: 10px;
            border: 1px solid red;
        }
    </style>
</head>
<body>
    <input type="text" id="foo">

    <button class="copy" data-clipboard-target="#foo">复制</button>
    <br>
    <input type="text">
</body>
<script>
    window.onload=function () {
        var clipboard = new Clipboard('.copy');
        clipboard.on('success', function(e) {
            alert('复制成功');
        });
    }
</script>
</html>